<?php
namespace classlib\core\middleware;
abstract class middleware {
	/**
	 * 指向下一个中间件资料
	 * @var middleware
	 */
	protected $next;
	
	/**
	 * 构造初始化中间件对象
	 * @param middleware $next
	 */
	public function __construct($next) {
		$this->next = $next;
	}
	
	/**
	 * 重置中间件下一个结点
	 * @param middleware $next
	 */
	public function set(middleware $next) {
		$this->next = $next;
	}
	
	/**
	 * 构建中间件然后返回顶级结点
	 * @param array 中间键列表
	 * @return middleware
	 */
	public static function build($args) {
		$srvname = array_shift($args); 
		$service = new $srvname(null);
		$pointer = $service;
		foreach ($args as $srvname) {
			$tsrv    = new $srvname(null);
			$pointer->set($tsrv);
			$pointer = $tsrv;
		}
		return $service;
	}
	
	/**
	 * 要实现的业务代码资料信息记录
	 * @return void
	 */
	abstract public function doservice();
}